﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KoshiDE;

namespace Solvers.Koshi
{
    public class EilerSolver:KoshiSolver
    {
        public EilerSolver(KoshiTask task)
            :base(task)
        {
            this.Solved = false;
        }

        public override void Solve()
        {
            double x = this.Task.A;
            double y = this.Task.Y0;
            double H = this.Task.H;
            double y1 = y;

            KoshiSolution sol = new KoshiSolution();

            for (double i = this.Task.A; i <= this.Task.B; i += this.Task.H)
            {
                double f1 = this.Task.funct(x, y);
                x += H;
                y += f1 * H;
                y = y1 + H * (f1 + this.Task.funct(x, y)) / 2.0;
                y1 = y;
                sol[i] = y1;
            }

            this.Solution = sol;
            this.Solved = true;
        }
    }
}
